public class t2432 {
    public static void main(String[] args) {
        int logs[][] = {{1, 1}, {3, 7}, {2, 12}, {7, 17}};
        int n = 26;
        System.out.println(hardestWorker(n, logs));
    }

    public static int hardestWorker(int n, int[][] logs) {
        int time = logs[0][1];
        int num = logs[0][0];
        int len = logs.length;

        for (int i = 1; i < len; i++) {
            int tmp = logs[i][1] - logs[i - 1][1];
            if (tmp > time) {
                if (logs[i][0] <= n){
                    num = logs[i][0];
                    time = tmp;
                }
            }else if(tmp==time){
                num = Math.min(num,logs[i][0]);
            }
        }
        return num;
    }
}
